package com.db.query;

import com.db.utils.QueryDslUtils;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.*;

/**
 * @author dzh
 * @since 2024/12/27
 */
public class QObject<T> extends EntityPathBase<T> {
    private Object queryParam;
    public QObject(Class<T> clazz, Object queryParam) {
        super(clazz, variable(clazz));
        this.queryParam = queryParam;
    }

    static String variable(Class<?> clazz) {
        char[] charArray = clazz.getSimpleName().toCharArray();
        charArray[0] = Character.toLowerCase(charArray[0]);
        return String.valueOf(charArray);
    }

    @Override
    public BooleanPath createBoolean(String property) {
        return super.createBoolean(property);
    }

    @Override
    public <A extends Enum<A>> EnumPath<A> createEnum(String property, Class<A> type) {
        return super.createEnum(property, type);
    }

    @Override
    public <A extends Comparable> DatePath<A> createDate(String property, Class<? super A> type) {
        return super.createDate(property, type);
    }

    @Override
    public <A extends Comparable> DateTimePath<A> createDateTime(String property, Class<? super A> type) {
        return super.createDateTime(property, type);
    }

    @Override
    public <A extends Number & Comparable<?>> NumberPath<A> createNumber(String property, Class<? super A> type) {
        return super.createNumber(property, type);
    }

    @Override
    public StringPath createString(String property) {
        return super.createString(property);
    }

    public <A extends Comparable> ComparablePath<A> createComparable(String property, Class<? super A> type) {
        return super.createComparable(property, type);
    }

    @Override
    public <A extends Comparable> TimePath<A> createTime(String property, Class<? super A> type) {
        return super.createTime(property, type);
    }

    public <T> Predicate predicate() {
        return QueryDslUtils.predicate(queryParam, this);
    }
}
